SHELL = bash -Eeuxo pipefail
.DEFAULT_GOAL := run

GUILE_LOAD_PATH_ADDITIONS := lib
GUILE_LOAD_PATH_ADDITIONS += lib/utils
GUILE_LOAD_PATH_ADDITIONS += lib/contracts

GUILE_LOAD_PATH_ARGUMENTS := -L . $(foreach dir,$(GUILE_LOAD_PATH_ADDITIONS),-L $(dir))

# Get the project directory somehow.
# PROJECT_DIR := "$(shell pwd)"
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR := $(patsubst %/,%,$(dir $(mkfile_path)))


.PHONY: build
build:
	guix time-machine \
		--channels="$(PROJECT_DIR)/guix-env/channels.scm" -- \
		shell \
		--development \
		--manifest="$(PROJECT_DIR)/guix-env/manifest.scm" -- \
		guile \
			--fresh-auto-compile \
			$(GUILE_LOAD_PATH_ARGUMENTS) \
			main.scm


.PHONY: run
run:
	exec guix time-machine \
		--channels="$(PROJECT_DIR)/guix-env/channels.scm" -- \
		shell \
		--development \
		--manifest="$(PROJECT_DIR)/guix-env/manifest.scm" -- \
		guile \
			$(GUILE_LOAD_PATH_ARGUMENTS) \
			-l main.scm
